const mongoose = require("mongoose")
mongoose.connect("mongodb://127.0.0.1/mongoose_test")
const Schema = mongoose.Schema
const studentsSchema = new Schema({
    name: String,
    age: {
        type: Number,
        min: 10,
        max: 50,
        required: true,
    },
    gender: {
        type: String,
        default: "male",

    }
})
// 创建一个model
const StudentsModel = mongoose.model("students", studentsSchema)
//  StudentsModel.create({
//     name: "shh",
//     age: 18
// }).then(res => {
//     console.log(res);
// })

// StudentsModel.find({}, "name -_id").exec().then(res => console.log(res))

// StudentsModel.find({}, { name: 1, _id: 0, age: 1 }, { skip: 1, sort: { age: -1 }, limit: 3 }).exec().then(res => console.log(res))

// StudentsModel.deleteOne({ name: "zzq" }).then(res => console.log(res))

// StudentsModel.updateOne({ name: "shh" }, { $set: { gender: "female" } }).then(res => console.log(res))

// StudentsModel.count({ name: "hwj", gender: "male" }).then(res => console.log(res))

// 创建一个Document
let studentsDoc = new StudentsModel({
    name: "wmk",
    age: 20,
    gender: "female"
})
// studentsDoc.save().then(res => console.log(res))
studentsDoc.deleteOne().then(res => console.log(res))
studentsDoc.save()